<template>
  <el-row>
    <el-col :span="24">
      <el-card>
        <el-form :inline="true" class="demo-form-inline">
          <!-- <el-form-item>
            <el-button type="success" style="margin-bottom: 10px;" @click="ShowAddDialog">添加</el-button>
          </el-form-item> -->
          <el-form-item>
          </el-form-item>
        </el-form>
        <el-table :data="pageInfo.list" border style="width: 100%">
          <el-table-column prop="oid" label="ID" />
          <el-table-column prop="admin.name" label="用户名" />
          <el-table-column prop="cars.eavatar" label="头像">
            <template #default="scope">
              <el-avatar shape="square" :size="50" :src="'http://localhost:8080/upload/' + scope.row.cars.eavatar" />
            </template>
          </el-table-column>
          <el-table-column prop="cars.cplate" label="车牌号" />
          <el-table-column prop="cars.brand" label="品牌" />
          <el-table-column prop="orderstime" label="下单时间" />
          <el-table-column prop="days" label="租赁天数" />
          <el-table-column prop="pay" label="总价格" />
          <el-table-column prop="admin.telephone" label="用户电话" />
          <el-table-column prop="ostate" label="订单状态">
            <template #default="scope">
              <span v-if="scope.row.ostate == 1">
                <el-tag type="primary">进行中</el-tag></span>
              <span v-else-if="scope.row.ostate == 2"> <el-button size="small" type="primary" @click="update(scope.row.oid)">过期还车</el-button></span>
              <span v-else="socpe.row.ostate == 3"> <el-tag type="erorr">已完成</el-tag></span>
            </template>
          </el-table-column>
        </el-table>
        <el-row class="row-bg" justify="center" style="margin-top: 20px;">
          <el-pagination background layout="prev, pager, next" v-model:current-page="pageInfo.pageNum"
            v-model:page-count="pageInfo.pages" @updare:current-page="usercars" />
        </el-row>

      </el-card>
    </el-col>
  </el-row>

</template>


<script setup>
import { ElMessage, UPDATE_MODEL_EVENT } from 'element-plus';
import { ref } from 'vue';
import ordersApi from '@/api/ordersApi';
import adminApi from '@/api/adminApi';
//用来搜索的关键字
const id = ref();
const pageInfo = ref({
  total: 0,
  pageSize: 0,
  pageNum: 0
});
//根据用户id查询
function usercars() {
  adminApi.longinfo()
    .then(resp => {
      id.value = resp.data.id;
      selectid(1, id.value);
    })
}
//修改状态
function update(id){
 ordersApi.update(id)
 .then(resp=>{
  if(resp.code==10000){
  ElMessage.success(resp.msg);
  usercars();
  }else{
    ElMessage.error(resp.msg)
  }
 })

}

//分页查询；  
function selectid(pageNum) {

  ordersApi.selectId(pageNum, id.value)
    .then(resp => {
      pageInfo.value = resp.data;

    });
}
//默认查询首页
usercars();
</script>

<style scoped></style>